<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<script src="js/jquery-1.8.0.js"></script>
<link rel="stylesheet" type="text/css" href="../css/maintable.css" ></link>
</head>

<body>
  角色: ${roleInfo.roleName }
   <form action="RoleServlet.do?flag=updateRoleMenu" method="post">          	
     	 <input type="hidden" name="roleId" value="${roleInfo.id }" >
     	 <table class="main_table">
     	 	<tr>
     	    	<th>一级</th>	<th>二级</th>
     	 	</tr>
     	 	<c:forEach var="m" items="${menulist}">
     	 		<tr>
     	 			<td>
     	 				<input type="checkbox" name="menuIds"  id="${m.id }" value="${m.id}" onclick="checkSubItem(this)">
     	 			    ${m.menuName }
     	 			</td>
     	 			<td>
     	 				<c:forEach var="m_sub" items="${m.subMenuList}">
     	 					<input type="checkbox" name="menuIds" class="${m.id}" value="${m_sub.id}" onclick="checkParent(${m.id})">${m_sub.menuName}<br />
     	 				</c:forEach>
     	 			
     	 			</td>
     	 		</tr>
     	 	</c:forEach>
     	 </table>
     	  <input type="submit" value="提交" onclick="return confirm('确定提交吗')" >
     </form>
     ${msg}
     
    <script>
   		var menuIdStr= "${menuIdStr}";
   		var menuIdArray =  menuIdStr.split(",");
   		Array.prototype.contains=function(e){
   			for(var i=0;i<this.length;i++){
   				if(this[i]==e){
   					return true;
   				}
   			}
   			return false;
   		}
   		$("input[name=menuIds]").each(function(){
   			if(menuIdArray.contains(this.value)){
   				this.checked=true;
   			}	
   		});
   		
		function checkSubItem(txtMenu){
			$("."+txtMenu.id).attr("checked",txtMenu.checked);
		}
	   	
		function checkParent(parentId){
   			$("#"+parentId).removeAttr("checked");
   			$("."+parentId).each(function(){
   				if(this.checked){
   					$("#"+parentId).attr("checked","checked");
   					return;
   				}
   			});	
   		}
     	
     </script>
</body>
</html>